from django.shortcuts import render
from .models import Person
from .models import Identity
from django.http import HttpResponse


# Create your views here.
# 添加preson
def add_preson(request):
    u_name = request.GET.get('u_name')
    p = Person.objects.create(p_name=u_name)
    return HttpResponse(f'创建成功, {p.p_name}')


# 添加identity
def add_identity(request):
    i_num = request.GET.get('num')
    p = Person.objects.last()
    i = Identity.objects.create(i_num=i_num, i_person=p)
    return HttpResponse(f'创建成功，{i.i_num}， 绑定成功{i.i_person}')


# 通过identity获取preson的信息
def get_preson(request):
    identity = Identity.objects.last()
    preson = identity.i_person
    return HttpResponse(f'{preson.p_name}')


# 通过preson获取identity信息
def get_identity(request):
    preson = Person.objects.last()
    identity = preson.identity
    return HttpResponse(f'{identity.i_num}')